//
//  GongLveViewCell.m
//  TravelYo
//
//  Created by lanou3g on 15/10/30.
//  Copyright © 2015年 TravelYo. All rights reserved.
//

#import "GongLveViewCell.h"

@implementation GongLveViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        [self addSubViews];
        
    }
    return self;
}

- (void)addSubViews
{
    UIView *backGroundView = [[UIView alloc] initWithFrame:CGRectMake(10, 0, kScreenWidth - 20, 110)];
    backGroundView.backgroundColor = [UIColor blueColor];
    backGroundView.alpha = 0.05;
    backGroundView.layer.cornerRadius = 10;
    backGroundView.layer.masksToBounds = YES;
    [self.contentView addSubview:backGroundView];
    

    
   // 标题
    self.titleLable = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, kScreenWidth - 20, 50)];
    //self.titleLable.backgroundColor = [UIColor brownColor];
    self.titleLable.numberOfLines = 0;
    [self.contentView addSubview:self.titleLable];
    
    // 用户名
    self.userNameLable = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLable.left, self.titleLable.bottom + 10, kScreenWidth / 4, 30)];
   // self.userNameLable.backgroundColor = [UIColor brownColor];
    [self.contentView addSubview:self.userNameLable];
    
    // 时间
    self.lastpostLable = [[UILabel alloc] initWithFrame:CGRectMake(self.userNameLable.right + 10, self.userNameLable.top, kScreenWidth / 3 , 30)];
    //self.lastpostLable.backgroundColor = [UIColor brownColor];
    [self.contentView addSubview:self.lastpostLable];
    
    // 评论
    self.replysLable = [[UILabel alloc] initWithFrame:CGRectMake(self.lastpostLable.right + 10, self.lastpostLable.top, kScreenWidth / 5 + 35, 30)];
    //self.replysLable.backgroundColor = [UIColor brownColor];
    [self.contentView addSubview:self.replysLable];
    
    
}

- (void)setGlModel:(GongLveModel *)glModel
{
    // 标题
    self.titleLable.text = glModel.title;
    self.titleLable.alpha = 0.8;
    // 用户名
    self.userNameLable.text = glModel.username;
    self.userNameLable.alpha = 0.6;
    // 时间
    NSDate *nowDate = [NSDate date];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:glModel.lastpost];
    NSTimeInterval subTimeInteval = [nowDate timeIntervalSinceDate:date];
    if (subTimeInteval < 60) {
        self.lastpostLable.text = @"刚刚";
        self.lastpostLable.alpha = 0.6;
    } else if (subTimeInteval >= 60 && subTimeInteval < 3600) {
        self.lastpostLable.text = [NSString stringWithFormat:@"%d分钟前", (int)subTimeInteval / 60];
        self.lastpostLable.alpha = 0.6;
    } else if (subTimeInteval >= 3600 && subTimeInteval < 24 * 3600) {
        self.lastpostLable.text = [NSString stringWithFormat:@"%d小时前",(int)subTimeInteval / 3600];
        self.lastpostLable.alpha = 0.6;
    }
    
    // 评论
    self.replysLable.text = [NSString stringWithFormat:@"评论:%@",glModel.replys];
    self.replysLable.alpha = 0.6;
    
}








- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
